/*
 * Copyright 2010    Sylvere RICHARD
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.infotrafficlux.server.controller;

import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;

import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.deser.StdDeserializer.LongDeserializer;
import org.codehaus.jackson.map.deser.StdDeserializer.StringDeserializer;
import org.codehaus.jackson.map.ser.BasicSerializerFactory.StringSerializer;

import com.google.appengine.api.datastore.GeoPt;
import com.google.infotrafficlux.server.admin.GeoPtDeserializer;
import com.google.infotrafficlux.server.admin.GeoPtSerializer;
import com.google.infotrafficlux.server.bean.Place;

@JsonSerialize(using=NewPlaceSerializer.class)
@JsonDeserialize(using=NewPlaceDeserializer.class)
public class NewPlace {

	public NewPlace() {
	}

	public NewPlace(Long id, String citaId, GeoPt location, String desc,
			String highway) {
		super();
		this.id = id;
		this.citaId = citaId;
		this.location = location;
		this.desc = desc;
		this.highway = highway;
	}

	@NotNull
	private Long id;

	@NotNull
	private String citaId;

	@NotNull
	@Max(value = 255)
	private String desc;

	@NotNull
	@Max(value = 5)
	private String highway;

	@NotNull
	private GeoPt location;

	//@JsonSerialize(using=LongSerializer.class)
	public Long getId() {
		return id;
	}

	@JsonDeserialize(using=LongDeserializer.class)
	public void setId(Long id) {
		this.id = id;
	}

	@JsonSerialize(using=StringSerializer.class) 
	public String getCitaId() {
		return citaId;
	}

	@JsonDeserialize(using=StringDeserializer.class)
	public void setCitaId(String citaId) {
		this.citaId = citaId;
	}

	@JsonSerialize(using=StringSerializer.class) 
	public String getDesc() {
		return desc;
	}

	@JsonDeserialize(using=StringDeserializer.class)
	public void setDesc(String desc) {
		this.desc = desc;
	}

	@JsonSerialize(using=StringSerializer.class) 
	public String getHighway() {
		return highway;
	}

	//@JsonDeserialize(using=StringDeserializer.class)
	public void setHighway(String highway) {
		this.highway = highway;
	}

	@JsonSerialize(using=GeoPtSerializer.class) 
	public GeoPt getLocation() {
		return location;
	}

    @JsonDeserialize(using=GeoPtDeserializer.class) 
	public void setLocation(GeoPt location) {
		this.location = location;
	}

	public Place asPlace() {
		Place p = new Place(id, citaId, location, desc, highway);
		return p;
	}

	@Override
	public String toString() {
		return "NewPlace [id=" + id + ", citaId=" + citaId + ", desc=" + desc
				+ ", highway=" + highway + ", location=" + location + "]";
	}
	
	

}
